package com.fire.social.mapper;

import com.fire.social.entity.node.Hobby;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface HobbyMapper extends Neo4jRepository<Hobby, Long> {

    /**
     * 获取所有兴趣爱好
     */
    @Query("match (hobby:Hobby) RETURN hobby")
    List<Hobby> getAllHobbies();

    /**
     * 获取用户兴趣爱好
     */
    @Query("match (user:User) where user.account=$account\n" +
            "match ((user)-[:Like]->(hobby:Hobby)) return hobby")
    List<Hobby> getHobbyByAccount(@Param("account") String account);

    /**
     * 创建兴趣爱好
     */
    @Query("create (hobby:Hobby{hname:$hname,htype:$htype}) return hobby")
    Hobby createHobby(@Param("hname") String hname, @Param("htype") String htype);

    /**
     * 查询兴趣爱好
     */
    @Query("match (hobby:Hobby) where hobby.hname=~$hname return hobby")
    List<Hobby> findHobbyByName(@Param("hname") String hname);
}
